#!/usr/bin/env python3
# -*-coding : utf-8 -*-
# @time     : 2019/9/22 0022 下午 4:56
# @Author   : Administrator
# @FileName : 简单的采集器.py
# --------------------------------------------------------

"""
处理个get请求的参数
简单的网页采集器
"""

import requests

# 用户的请求参数
wd = input("enter a word:")

# 1.指定url
url = "https://www.sogou.com/web"
# 参数的封装
params = {
    'query': wd
}
# UA伪装
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
}
# 2.发起请求
response = requests.get(url=url, params=params, headers=headers)
# 中文乱码，手动修改响应数据的编码
response.encoding = "utf8"
# 3.获取响应数据
page_text = response.text
# 4.持久化存储
file_name = "{0}.html".format(wd)
with open(file_name, 'w', encoding="utf8") as f:
    f.write(page_text)
print(file_name, "爬取成功!")
